<template>
<view :class="'_root ' + (selectable?'_select':'')"><slot v-if="!nodes[0]"></slot><node id="_root" :childs="nodes" :opts="[lazyLoad,loadingImg,errorImg,showImgMenu]" catchadd="_add"></node></view>
</template>

<script>
"use strict";
function e(e, t, n) {
  return t in e ? Object.defineProperty(e, t, {
    value: n,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = n, e;
}
/*!
 * mp-html v2.0.4
 * https://github.com/jin-yufeng/mp-html
 * 
 * Released under the MIT license
 * Author: Jin Yufeng
 */
/*!
 * mp-html v2.0.4
 * https://github.com/jin-yufeng/mp-html
 * 
 * Released under the MIT license
 * Author: Jin Yufeng
 */
var t = require("./parser.js"),
    n = [];
import node from "./node/node";

export default {
  data() {
    return {
      nodes: []
    };
  },

  components: {
    node
  },
  props: {
    content: {
      type: String,
      default: ""
    },
    copyLink: {
      type: Boolean,
      default: !0
    },
    domain: String,
    errorImg: String,
    lazyLoad: Boolean,
    loadingImg: String,
    pauseVideo: {
      type: Boolean,
      default: !0
    },
    previewImg: {
      type: Boolean,
      default: !0
    },
    scrollTable: Boolean,
    selectable: Boolean,
    setTitle: {
      type: Boolean,
      default: !0
    },
    showImgMenu: {
      type: Boolean,
      default: !0
    },
    tagStyle: Object,
    useAnchor: null
  },
  watch: {
    content: {
      handler: function (e) {
        this.setContent(e);
      },
      immediate: true
    }
  },
  created: function () {
    this.plugins = [];

    for (var e = n.length; e--;) this.plugins.push(new n[e](this));
  },
  destroyed: function () {
    clearInterval(this._timer), this.hookFun("onDetached");
  },
  methods: {
    inFun: function (e, t, n) {
      e && t && n && (this._in = {
        page: e,
        selector: t,
        scrollTop: n
      });
    },
    navigateTo: function (t, n) {
      var o = this;
      return new Promise(function (i, r) {
        if (!o.useAnchor) return r("Anchor is disabled");
        var a = uni.createSelectorQuery().in(o._in ? o._in.page : o).select((o._in ? o._in.selector : "._root") + (t ? "".concat(">>>", "#").concat(t) : "")).boundingClientRect();
        o._in ? a.select(o._in.selector).scrollOffset().select(o._in.selector).boundingClientRect() : a.selectViewport().scrollOffset(), a.exec(function (t) {
          if (!t[0]) return r("Label not found");
          var a = t[1].scrollTop + t[0].top - (t[2] ? t[2].top : 0) + (n || parseInt(o.useAnchor) || 0);
          o._in ? o._in.page.setData(e({}, o._in.scrollTop, a)) : uni.pageScrollTo({
            scrollTop: a,
            duration: 300
          }), i();
        });
      });
    },
    getText: function () {
      var e = "";
      return function t(n) {
        for (var o = 0; o < n.length; o++) {
          var i = n[o];
          if ("text" == i.type) e += i.text.replace(/&amp;/g, "&");else if ("br" == i.name) e += "\n";else {
            var r = "p" == i.name || "div" == i.name || "tr" == i.name || "li" == i.name || "h" == i.name[0] && i.name[1] > "0" && i.name[1] < "7";
            r && e && "\n" != e[e.length - 1] && (e += "\n"), i.children && t(i.children), r && "\n" != e[e.length - 1] ? e += "\n" : "td" != i.name && "th" != i.name || (e += "\t");
          }
        }
      }(this.nodes), e;
    },
    getRect: function () {
      var e = this;
      return new Promise(function (t, n) {
        uni.createSelectorQuery().in(e).select("._root").boundingClientRect().exec(function (e) {
          return e[0] ? t(e[0]) : n("Root label not found");
        });
      });
    },
    setContent: function (e, n) {
      var o = this;
      this.imgList && n || (this.imgList = []), this._videos = [];
      var i = {},
          r = new t(this).parse(e);
      if (n) for (var a = this.nodes.length, l = r.length; l--;) i["nodes[".concat(a + l, "]")] = r[l];else i.nodes = r;
      this.setData(i, function () {
        o.hookFun("onLoad"), o.$emit("load");
      });
      var s;
      clearInterval(this._timer), this._timer = setInterval(function () {
        o.getRect().then(function (e) {
          e.height == s && (o.$emit("ready", {
            detail: e
          }), clearInterval(o._timer)), s = e.height;
        }).catch(function () {});
      }, 350);
    },
    hookFun: function (e) {
      for (var t = n.length; t--;) this.plugins[t][e] && this.plugins[t][e]();
    },
    addFun: function (e) {
      e.detail.root = this;
    }
  }
};
</script>
<style>
._root{overflow:hidden;-webkit-overflow-scrolling:touch}._select{-webkit-user-select:text;user-select:text}
</style>